package com.olymtech.jbricks.dingtalk.message.delivery.msg;

import com.dingtalk.api.request.OapiMessageCorpconversationAsyncsendV2Request;
import com.olymtech.jbricks.dingtalk.message.LinkMessage;
import com.olymtech.jbricks.dingtalk.message.Message;
import com.olymtech.jbricks.dingtalk.message.TextMessage;
import com.taobao.api.TaobaoObject;

/**
 * @author haoting.wang
 * @date 2020/12/10 2:36 下午
 **/
public class WorkMessageService {

    public static TaobaoObject convertText(Message message) {

        TextMessage textMessage = (TextMessage) message;

        OapiMessageCorpconversationAsyncsendV2Request.Msg msg = new OapiMessageCorpconversationAsyncsendV2Request.Msg();
        OapiMessageCorpconversationAsyncsendV2Request.Text text = new OapiMessageCorpconversationAsyncsendV2Request.Text();
        text.setContent(textMessage.content);

        msg.setMsgtype(textMessage.type().getType());
        msg.setText(text);

        return msg;

    }

    public static TaobaoObject convertLink(Message message) {

        LinkMessage linkMessage = (LinkMessage) message;

        // link消息
        OapiMessageCorpconversationAsyncsendV2Request.Msg msg = new OapiMessageCorpconversationAsyncsendV2Request.Msg();

        OapiMessageCorpconversationAsyncsendV2Request.Link link = new OapiMessageCorpconversationAsyncsendV2Request.Link();
        link.setMessageUrl(linkMessage.messageUrl);
        link.setPicUrl(linkMessage.picUrl);
        link.setText(linkMessage.text);
        link.setTitle(linkMessage.title);

        msg.setMsgtype(linkMessage.type().getType());
        msg.setLink(link);
        return msg;
    }

}